#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)

__license__   = 'GPL v3'
__copyright__ = '2013, Ida Leter'
__copyright__ = '2011, Jim Miller'
__docformat__ = 'restructuredtext en'

from PyQt4.Qt import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QTextEdit,
                      QComboBox, QCheckBox)

from calibre.utils.config import JSONConfig

from calibre_plugins.astroph_plugin.dialogs import (OVERWRITE, ADDNEW, SKIP)

# This is where all preferences for this plugin will be stored
# Remember that this name (i.e. plugins/astroph_plugin) is also
# in a global namespace, so make it as unique as possible.
# You should always prefix your config file name with plugins/,
# so as to ensure you dont accidentally clobber a calibre config file
prefs = JSONConfig('plugins/astroph_plugin')

# Set defaults
prefs.defaults['collision'] = SKIP
prefs.defaults['urlsfromclip'] = True

class ConfigWidget(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.l = QVBoxLayout()
        self.setLayout(self.l)

        horz = QHBoxLayout()
        label = QLabel('Default On &Collision?')
        label.setToolTip("What to do if there's already an existing paper with the same title and author.")
        horz.addWidget(label)
        self.collision = QComboBox(self)
        self.collision.addItem(OVERWRITE)
        self.collision.addItem(ADDNEW)
        self.collision.addItem(SKIP)
        self.collision.setCurrentIndex(self.collision.findText(prefs['collision']))
        self.collision.setToolTip('Overwrite will replace the existing paper.  Add New will create a new paper with the same title and author.')
        label.setBuddy(self.collision)
        horz.addWidget(self.collision)
        self.l.addLayout(horz)
        
        self.urlsfromclip = QCheckBox('Take URLs from Clipboard?',self)
        self.urlsfromclip.setToolTip('Prefill URLs from valid URLs in Clipboard when Adding New?')
        self.urlsfromclip.setChecked(prefs['urlsfromclip'])
        self.l.addWidget(self.urlsfromclip)
        
    def save_settings(self):
        prefs['collision'] = unicode(self.collision.currentText())
        prefs['urlsfromclip'] = self.urlsfromclip.isChecked()